﻿Imports System.Data.SqlClient

Public Class clsFORMULARIOS
    Private cnConn As New SqlConnection
    Private Command As SqlCommand
    Public Sub ABRE_FORMULARIO(ByVal NOMBRE As String, ByVal UBICACION As String)

        Dim sql As String = "Insert Into FORMULARIOS_ABIERTOS " & _
                       "VALUES (" & _
                       "@FORMULARIO," & _
                       "@USUARIO," & _
                       "@UBICACION)"



        Dim cnConns As New SqlConnection
        cnConns.ConnectionString = CitraConnection

        Dim Commands As New SqlCommand(sql, cnConns)

        Commands.Parameters.AddWithValue("FORMULARIO", NOMBRE)
        Commands.Parameters.AddWithValue("USUARIO", UsuarioActivo)
        Commands.Parameters.AddWithValue("UBICACION", UBICACION)

        cnConns.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Commands.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConns.Close()
            Else
                If cnConns.State = ConnectionState.Open Then
                    cnConns.Close()
                End If
            End If
        Catch ex As Exception
            If cnConns.State = ConnectionState.Open Then
                cnConns.Close()
            End If
        End Try
    End Sub
    Public Sub CONECTA_FORMULARIOS()
        cnConn.ConnectionString = CitraConnection

        Command = New SqlCommand("HISTORIA_FORMULARIOS", cnConn)
        Command.CommandType = CommandType.StoredProcedure
        Command.CommandTimeout = 0


        Command.Parameters.Add(New SqlParameter("@FORMULARIO", SqlDbType.VarChar, 100))
        Command.Parameters.Add(New SqlParameter("@DESCRIPCION", SqlDbType.VarChar, 300))
        Command.Parameters.Add(New SqlParameter("@USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))

        Try
            cnConn.Open()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Public Sub ACTUALIZA_FORMULARIO(ByVal NOMBRE As String, ByVal DESCRIPCION As String, ByVal TIPO As Integer)
        Command.Parameters("@FORMULARIO").Value = NOMBRE
        Command.Parameters("@DESCRIPCION").Value = DESCRIPCION
        Command.Parameters("@USUARIO").Value = UsuarioActivo
        Command.Parameters("@TIPO").Value = TIPO

        Try
            Command.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")

        End Try


    End Sub
    Public Sub DESCONECTA_FORMULARIOS()
        If cnConn.State = ConnectionState.Open Then
            cnConn.Close()
        End If
    End Sub
    Public Sub ACTUALIZA_UBICACION(ByVal NOMBRE As String, ByVal UBICACION As String)
        Call SetSqlCitra("UPDATE FORMULARIOS_ABIERTOS SET UBICACION='" & UBICACION & "' WHERE FORMULARIO='" & NOMBRE & "' AND USUARIO='" & UsuarioActivo & "'")
    End Sub
    Public Sub CIERRA_FORMULARIO(ByVal NOMBRE As String)
        Call SetSqlCitra("DELETE FROM FORMULARIOS_ABIERTOS WHERE USUARIO='" & UsuarioActivo & "' AND FORMULARIO='" & NOMBRE & "'")
    End Sub
End Class
